package com.gjy.minio.config;

import com.gjy.minio.properties.MinioYaml;
import io.minio.MinioClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2023-09-04 20:05:37
 */
@Configuration
public class MinioConfig {

    private static final Logger log = LoggerFactory.getLogger(MinioConfig.class);

    @Resource
    private MinioYaml minioYaml;

    @Bean(name = "minio")
    public MinioClient minio() {

        log.info("minio yaml: {}", minioYaml);

        return MinioClient.builder()
                .endpoint(minioYaml.getAddress())
                .credentials(minioYaml.getUsername(), minioYaml.getPassword())
                .build();
    }
}
